package com.example.dllo.my36kr.ui.fragment;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnticipateInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.my36kr.R;
import com.example.dllo.my36kr.ui.activity.sonactivity.SearchActivity;
import com.example.dllo.my36kr.ui.adapter.InvestTabAdapter;
import com.example.dllo.my36kr.ui.fragment.investtabfragment.InvestRaiseFragment;
import com.example.dllo.my36kr.ui.fragment.investtabfragment.InvestTabAllFragment;
import com.example.dllo.my36kr.ui.fragment.investtabfragment.InvestfinishFragment;
import com.example.dllo.my36kr.ui.fragment.investtabfragment.investSuccessFragment;
import java.util.ArrayList;
/**股权投资界面
 * Created by CPC_272 on 16/8/15.
 */
public class InvestFragment extends AbsBaseFragment implements View.OnClickListener {
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private ImageView mSearch_image, edit_img,present_img,image_present_center;
    private ArrayList<Fragment>datas;
    @Override
    protected int setLayout() {
        return R.layout.fragment_invest;
    }

    @Override
    protected void initView() {
        tabLayout=byView(R.id.tab_invest);
        viewPager = byView(R.id.vp_invest);
        mSearch_image = byView(R.id.invest_search);//搜索
        edit_img = byView(R.id.edit_present_img);//x
        image_present_center = byView(R.id.image_present_center);//图片
        present_img = byView(R.id.present_img);//盒子符号
    }
    @Override
    protected void initData() {
        //以下两行代码是为了盒子没点击的时候不可见
        edit_img.setVisibility(View.GONE);
        image_present_center.setVisibility(View.GONE);

        mSearch_image.setOnClickListener(this);
        present_img.setOnClickListener(this);
        edit_img.setOnClickListener(this);
        image_present_center.setOnClickListener(this);
        datas=new ArrayList<>();
        datas.add(new InvestTabAllFragment());//全部
        datas.add(new InvestRaiseFragment());//募资中
        datas.add(new InvestfinishFragment());//募资完成
        datas.add(new investSuccessFragment());//融资成功
        InvestTabAdapter investTabAdapter=new InvestTabAdapter(getActivity().getSupportFragmentManager(),datas);//因为没继承activity所以我用getActivity引出来
        viewPager.setAdapter(investTabAdapter);
        tabLayout.setupWithViewPager(viewPager);

    }

    @Override
    public void onClick(View v) {
       switch (v.getId()){
           case R.id.invest_search://搜索
               Intent intent = new Intent(context, SearchActivity.class);
                context.startActivity(intent);
               break;
           case R.id.present_img://点开盒子里东西出来 (X和图片都可见)
               edit_img.setVisibility(View.VISIBLE);
               image_present_center.setVisibility(View.VISIBLE);
               break;
           case  R.id.edit_present_img://点击X盒子里面东西关闭 (X和图片都不可见)
               edit_img.setVisibility(View.GONE);
               image_present_center.setVisibility(View.GONE);
               //盒子加上动画效果 旋转动画
               RotateAnimation rAnime = new RotateAnimation(-45, 45, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
               rAnime.setDuration(100);
               rAnime.setRepeatCount(4);
               rAnime.setRepeatMode(Animation.REVERSE);
               rAnime.setInterpolator(new AnticipateInterpolator());
               rAnime.setInterpolator(new AccelerateInterpolator());
               present_img.startAnimation(rAnime);
               break;
       }
    }
}
